#!/bin/bash

# 构建各平台启动器脚本

echo "Building launchers..."

# 检查Go是否已安装
if ! command -v go &> /dev/null
then
    echo "Error: Go is not installed or not in PATH"
    echo "Please install Go 1.21+ from https://golang.org/dl/"
    exit 1
fi

# 创建bin目录（如果不存在）
mkdir -p bin

# 构建Windows 64位启动器
echo "Building Windows 64-bit launcher..."
GOOS=windows GOARCH=amd64 go build -o bin/launcher_windows.exe src/launcher/main.go
if [ $? -ne 0 ]; then
    echo "Error: Failed to build Windows 64-bit launcher"
    exit 1
fi

echo "Windows 64-bit launcher built successfully: bin/launcher_windows.exe"

# 构建Linux 64位启动器 (x86)
echo "Building Linux 64-bit launcher (x86)..."
GOOS=linux GOARCH=amd64 go build -o bin/launcher_linux_x86 src/launcher/main.go
if [ $? -ne 0 ]; then
    echo "Error: Failed to build Linux 64-bit launcher (x86)"
    exit 1
fi

echo "Linux 64-bit launcher (x86) built successfully: bin/launcher_linux_x86"

# 构建Linux ARM启动器
echo "Building Linux ARM launcher..."
GOOS=linux GOARCH=arm go build -o bin/launcher_linux_arm src/launcher/main.go
if [ $? -ne 0 ]; then
    echo "Error: Failed to build Linux ARM launcher"
    exit 1
fi

echo "Linux ARM launcher built successfully: bin/launcher_linux_arm"

# 构建Linux ARM64启动器
echo "Building Linux ARM64 launcher..."
GOOS=linux GOARCH=arm64 go build -o bin/launcher_linux_arm64 src/launcher/main.go
if [ $? -ne 0 ]; then
    echo "Error: Failed to build Linux ARM64 launcher"
    exit 1
fi

echo "Linux ARM64 launcher built successfully: bin/launcher_linux_arm64"

echo ""
echo "All launchers built successfully!"
echo ""
echo "To use PyInstallerEx, run:"
echo "  python -m PyInstallerEx test/test_script.py --cfg test/test_config.json"

exit 0